package com.example.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//用来配置项目需求的配置

//告诉springboot这个类属于配置类 并且将实例化对象扫描到ioc容器中


//@Configuration
public class MyMVCconfig implements WebMvcConfigurer {

    //可以自定义请求，使得请求只想真正想要去的页面
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login").setViewName("login");
    }

    //拿到对应拦截规则的对象
    @Autowired
    MyIntercepter myIntercepter;

    //配置拦截规则

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //调用对应的拦截规则的对象
        registry.addInterceptor(myIntercepter)
                //任何请求都需要进行被拦截
                .addPathPatterns("/**")
                //除了哪些请求可以不用被拦截
                .excludePathPatterns("/login", "/log", "/tologin", "/css/**", "/img/**", "/js/**");
    }
}
